package ifmo.compiler.task21.parser;

import ifmo.compiler.task21.parser.symbols.Symbol;
import java.util.HashMap;
import java.util.HashSet;


public class SpecialGrammarFunction {
	private HashMap<Symbol, HashSet<Symbol>> _set;
	
	public SpecialGrammarFunction()
	{
		_set = new HashMap<Symbol, HashSet<Symbol>>();
	}
	
	public void insert(Symbol key, Symbol value)
	{
		HashSet<Symbol> set;
		if (_set.containsKey(key))
		{
			set = _set.get(key);
		} else 
		{
			set = new HashSet<Symbol>();
			_set.put(key, set);
		}
		
		set.add(value);
	}
	
	public boolean contains(Symbol key, Symbol value)
	{
		if (_set.containsKey(key))
		{
			return _set.get(key).contains(value);
		}
		return false;
	}
	
	public HashSet<Symbol> getValues(Symbol key)
	{
		if (_set.containsKey(key))
		{
			return _set.get(key);
		}
		return new HashSet<Symbol>();
	}
	
	public void clear()
	{
		_set.clear();
	}
}
